local fengeng = fk.CreateSkill{
  name = "lingling__fengeng",
}

Fk:loadTranslationTable{
  ["lingling__fengeng"] = "分羹",
  [":lingling__fengeng"] = "每轮各限一次，当其他角色使用【桃】或【无中生有】后，你可以将一张牌当同名牌使用。",

  ["#lingling__fengeng-invoke"] = "分羹：你可以将一张牌当【%arg】使用",

  ["lingling__fengeng_EasterEgg"] = "吾翁即若翁，必欲烹而翁，则幸分我一杯羹。",
}

fengeng:addEffect(fk.CardUseFinished, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(fengeng.name) and target ~= player and
      (data.card.trueName == "peach" or data.card.trueName == "ex_nihilo") and
      player:canUse(Fk:cloneCard(data.card.name)) and
      not player:isNude() then
        if target.general == "lingling__xiangyu" and player.general == "lingling__liubang" then
          return not table.contains(player:getTableMark("lingling__fengeng_EasterEgg"), data.card.trueName)
        else
          return not table.contains(player:getTableMark("lingling__fengeng-round"), data.card.trueName)
        end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local use = room:askToUseVirtualCard(player, {
      name = data.card.name,
      skill_name = fengeng.name,
      prompt = "#lingling__fengeng-invoke:::"..data.card.name,
      cancelable = true,
      card_filter = {
        n = 1,
      },
      skip = true,
    })
    if use then
      event:setCostData(self, {extra_data = use})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if target.general == "lingling__xiangyu" and player.general == "lingling__liubang" and not table.contains(player:getTableMark("lingling__fengeng_EasterEgg"), data.card.trueName) then
      room:addTableMark(player, "lingling__fengeng_EasterEgg", data.card.trueName)
      room:sendLog{
        type = "#lingling__fengeng_EasterEgg",
        from = player.id,
        toast = true,
      }
    else
      room:addTableMark(player, "lingling__fengeng-round", data.card.trueName)
    end
    room:useCard(event:getCostData(self).extra_data)
  end,
})

fengeng:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "lingling__fengeng-round", 0)
end)

return fengeng
